package br.com.chat.utils;

import java.rmi.Naming;
import java.rmi.Remote;

import br.com.chat.rmi.ChatManager;
import br.com.chat.rmi.MessageReceiver;
import br.com.chat.rmi.MessageSender;

public class RemoteUtil {

    private static final String PREFIX = "rmi://192.168.5.71:1209/";

    public static MessageSender loadSender() {
        return (MessageSender) load("sender");
    }
    
    public static ChatManager loadManager(){
        return (ChatManager) load("manager");
    }
    
    public static MessageReceiver loadReceiver(){
        return (MessageReceiver) load("receiver");
    }

    private static Remote load(String name) {
        try {
            return Naming.lookup(PREFIX + name);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
